<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body {
            width: 100%;
            height: 100%;
        }
        
        input {
            width: 500px;
            margin: 100px auto;
            text-align: center;
        }
        
        button {
            display: inline-block;
            height: 200px;
            width: 200px;
            background-color: #ff4400;
        }
        
        input:nth-child(6) {
            margin: 100px 284px;
            font-size: 50px;
            text-align: center;
            width: 700px;
        }
        
        h1 {
            margin: 100px 366px;
            font-size: 50px;
        }
        
        h1 span {
            font-size: 20px;
            color: #ccc;
        }
    </style>
</head>

<body>
    <h1>猜拳游戏<span>1代表石头 2代表剪刀 3代表 布</span></h1>
    <input type="text" name="" id="num" placeholder="请出1代表石头 2代表剪刀 3代表 布">
    <button id="btn">PK</button>
    <input type="text" name="" id="num1" placeholder="电脑自动出">
    <br>
    <input type="text" name="" id="end">
    <script>
        document.getElementById("btn").onclick = function() {
            var _num = Number(document.getElementById("num").value);
            var _num1 = parseInt((Math.random("num1") * 3) + 1);
            document.getElementById("num1").value = _num1;
            if (_num === 1) {
                switch (_num1) {
                    case _num1 = 1:
                        document.getElementById("end").value = "平局";
                        break;
                    case _num1 = 2:
                        document.getElementById("end").value = "你赢了";
                        break;
                    case _num1 = 3:
                        document.getElementById("end").value = "你输了";
                        break;
                    default:
                        document.getElementById("end").value = "error";
                        break;
                }
            } else if (_num === 2) {
                switch (_num1) {
                    case _num1 = 1:
                        document.getElementById("end").value = "你输了";
                        break;
                    case _num1 = 2:
                        document.getElementById("end").value = "平局";
                        break;
                    case _num1 = 3:
                        document.getElementById("end").value = "你赢了";
                        break;
                    default:
                        document.getElementById("end").value = "error";
                        break;
                }
            } else if (_num === 3) {
                switch (_num1) {
                    case _num1 = 1:
                        document.getElementById("end").value = "你赢了";
                        break;
                    case _num1 = 2:
                        document.getElementById("end").value = "你输了";
                        break;
                    case _num1 = 3:
                        document.getElementById("end").value = "平局";
                        break;
                    default:
                        document.getElementById("end").value = "error";
                        break;
                }
            } else {
                document.getElementById("end").value = "请规范参赛，谢谢合作";
            }
        }
    </script>
</body>

</html>